<script setup lang="jsx">
  import {watch,inject,ref,reactive,computed} from 'vue'
  import customerAddress from '@/api/customers/customerAddress'
  const crudRef = ref()
  const record = inject('record')
  let options = reactive({
      id: 'customer_address',
      pk: 'id',
      showTools:false,
      autoRequest: record.value.id > 0,
      isDbClickEdit: true,
      expandSearch:false,
      api: customerAddress.getList,
      operationColumn: true,
      operationColumnText: '操作',
      operationColumnAlign: 'center',
      operationColumnWidth: 160,
      tablePagination:{style:{display:"none"}},
      rowSelection: {
        showCheckedAll: false
      },
      formOption: {
        viewType: 'drawer',
        width: '70%',
      },
      contextMenu: {
        // 是否开启右键菜单
        enabled: false,
      },
      beforeRequest:(param)=>{
        param.customer_id = record.value.id
        return param
      },
      beforeAdd:(param)=>{
        param.customer_id = record.value.id
        return param
      },
      add:{
        show: true,
        api: customerAddress.save,
      },
      edit:{
        api: customerAddress.update,
        show: true
      },
      delete: {
        show: true,
        batch: false,
        api: customerAddress.deletes,
      },
    })

    const columns = reactive([
  {
    title: "主键",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入主键"
    }
  },
  {
    title: "地址简称",
    dataIndex: "address_name",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入地址简称"
    }
  },
  {
    title: "类型",
    dataIndex: "type",
    formType: "select",
    // search: true,
    commonRules: {
      required: true,
      message: "请输入类型"
    },
    dict: {
      name: "addressType",
      props: {
        label: "title",
        value: "key"
      },
      translation: true
    }
  },
  {
    title: "联系人",
    dataIndex: "name",
    formType: "input",
    
    commonRules: {
      required: true,
      message: "请输入联系人"
    }
  },
  {
    title: "公司",
    dataIndex: "company",
    formType: "input"
  },
  {
    title: "电话",
    dataIndex: "tel",
    formType: "input"
  },
  {
    title: "手机",
    dataIndex: "mobile",
    formType: "input",
  },
  {
    title: "地址一",
    dataIndex: "address_1",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入地址"
    }
  },
  {
    title: "地址二",
    dataIndex: "address_2",
    formType: "input",
  },
  {
    title: "地址三",
    dataIndex: "address_3",
    formType: "input",
  },
  {
    title: "城市",
    dataIndex: "city",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入城市"
    }
  },
  {
    title: "省/州",
    dataIndex: "state",
    formType: "input"
  },
  {
    title: "邮编",
    dataIndex: "postcode",
    formType: "input",
    commonRules: {
      required: true,
      message: "请输入邮编"
    }
  },
  {
    title: "国家",
    dataIndex: "country",
    formType: "select",
    dict:{
      name: "countrys",
    },
    commonRules: {
      required: true,
      message: "请输入国家"
    }
  },
  {
    title: "默认地址",
    dataIndex: "default",
    formType: "switch",
    commonRules: {
      message: "请输入默认地址"
    },
    checkedValue: 1,
    uncheckedValue: 0
  },
  {
    title: "创建者",
    dataIndex: "created_by",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "备注",
    dataIndex: "remark",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true
  }
])
</script>

<template>
  <ma-crud :options="options" :columns="columns" ref="crudRef">

  </ma-crud>
</template>

<style>
.hidden-list ._crud-header,.hidden-list .mb-2,.hidden-list .operation-tools,.hidden-list .mb-1{
  display:none;
}

</style>